#include "DataSubscribe.h"
#include <QVariant>
#include "LibraryLoader.h"
#include "Publisher.h"
#include <QDebug>
DataSubscribe::DataSubscribe()
{
    //shares = new SharedData();
}

DataSubscribe::~DataSubscribe()
{
    //delete shares;
}


void DataSubscribe::Setup(ModuleInfo &mi)
{
    std::string assemblyName = mi.AssemblyName;
    std::string className = mi.ClassName;
    dataName = className;
    Publisher* pModule = nullptr;// = (BaseModule)Assembly.LoadFile(Path.GetFullPath(@".\" + assemblyName)).CreateInstance(className);
    pModule = LibraryLoader::load<Publisher>(assemblyName);
    if( pModule == nullptr )
    {
        //        qCritical() << LOG_HEADER << " load " << szPlugin.c_str() << " failed.";
        return;
    }
    if( pModule == nullptr )
    {

        qCritical() << __FILE__ << __LINE__ << " " << assemblyName.c_str() << " load failed.";
        return;
    }

    {
        Publisher* runable = dynamic_cast<Publisher*>(pModule);
        //runable->shares(shares);
        connect(runable, SIGNAL(pubData(const QString& ,const QString& ,const QVariant& )), dataConsumer, SLOT(OnData(const QString& ,const QString& ,const QVariant&)));
        runable->Run();
    }
}



std::string DataSubscribe::getTypeList()
{
    return "DataStorage::RunnableModule";
}

// void DataSubscribe::setLoader(QLibrary *)
// {

// }

void DataSubscribe::regConsumer(DataConsumer *dc)
{
    dataConsumer = dc;
    qDebug() << "register consumer";
}






